import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios';  //npm 下载的直接引入就行
// 引用Echarts
import * as echarts from 'echarts';



// 配置axios
axios.defaults.baseURL = 'http://wish.byesame.com/'  //配置服务器默认请求地址
axios.interceptors.request.use((config) => {

  config.headers.token = localStorage.getItem('token')

  return config
})
//请求拦截器
axios.interceptors.response.use((response) => {
  console.log('response', response)
  if (response.data.code == 401) {//如果token失效，删除token，刷新页面
    localStorage.removeItem('token');
    window.location.reload()//刷新页面
  }
  //响应拦截器
  return response
}, (err) => { console.log(err) })



Vue.prototype.$echarts = echarts;
Vue.use(ElementUI);
Vue.config.productionTip = false
Vue.prototype.$axios = axios

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')




